package com.clps.threadPool.test01;

import org.apache.commons.collections.CollectionUtils;
import org.w3c.dom.stylesheets.LinkStyle;

import java.util.ArrayList;
import java.util.List;

public class LoopTask {
    private List<ChildTask> childTasks;

    public  void  initLoopTask(){
        childTasks = new ArrayList<>();
        childTasks.add(new ChildTask("childTask1"));
        childTasks.add(new ChildTask("childTask2"));
        for (final ChildTask childTask : childTasks) {
            new Thread(()->{
                childTask.doExecute();
            }).start();
        }
    }

    public  void shutDownLoopTask(){
        if(!CollectionUtils.isEmpty(childTasks)){
            for (ChildTask childTask : childTasks) {
                childTask.terminal();
            }
        }
    }

    public static void main(String[] args) {
        LoopTask loopTask = new LoopTask();
        loopTask.initLoopTask();
        try {
            Thread.sleep(500L);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        loopTask.shutDownLoopTask();
    }
}
